﻿@using HGShare.Site
@using HGShare.Site.Config
@using HGShare.VWModel
@using Webdiyer.WebControls.Mvc
@model PagedList<UserVModel>
@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_HContentLayout.cshtml";
}
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>用户列表</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form action="@Url.Action("Index", "Users")" method="GET">
                        <div class="row">
                            <div class="col-sm-5 m-b-xs">
                                <div class="btn-group hidden-xs" role="group">
                                    <a href="@Url.Action("Add","Users")" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true"></i> 添加
                                    </a>
                                    <button class="btn btn-default btn-outline" type="button" name="refresh" title="刷新" id="pagereload">
                                        <i class="glyphicon glyphicon-repeat"></i> 刷新
                                    </button>
                                    <button type="button" class="btn btn-outline btn-default" id="deletessubmit">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i> 删除
                                    </button>
                                </div>
                            </div>
                            <div class="col-sm-4 m-b-xs">
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group">
                                    <input type="hidden" name="page" value="1" />
                                    <input type="text" name="username" placeholder="请输入关键词" class="input-sm form-control" value="@ViewBag.UserName">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th>
                                    <div class="checkbox checkbox-inline checkbox-primary">
    <input type="checkbox" value="0" id="selectdeleteitem" />
    <label for="selectdeleteitem"></label>
</div></th>
                                    <th>用户名</th>
                                    <th>头像</th>
                                    <th>昵称</th>
                                    <th>角色</th>
                                    <th>邮箱</th>
                                    <th>禁用</th>
                                    <th>最后在线时间</th>
                                    <th>最后操作时间</th>
                                    <th>创建时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (UserVModel item in Model)
                                {
                                    <tr>
                                        <td>
                                            <div class="checkbox checkbox-inline checkbox-primary">
                                                <input type="checkbox" value="@item.Id" id="deleteitem_@item.Id" name="deleteitem" />
                                                <label for="deleteitem_@item.Id"></label>
                                            </div>
                                        </td>
                                        <th scope="row">@item.Name</th>
                                        <th scope="row">
                                            <a href="@Url.Action("UploadAvatar", "Users",new{id=item.Id})">
                                                <img class="roundavatarimg s45" src="@(Tools.GenerateAvatar(item.Avatar, 45, item.Sex))" />
                                            </a>
                                        </th>
                                        <td>@item.NickName</td>
                                        <td>@item.RName</td>
                                        <td>@item.Email</td>
                                        <td>
                                            <input type="checkbox" data-id="@item.Id" class="disable-switch" @(item.Disable ? "checked" : "") title="@(item.Disable? "已禁用" : "未禁用")" />
                                            <a class="@((item.Disable&& !string.IsNullOrEmpty(item.DisableReason)) ? "" : "hidden")" id="disable-refusereason@(item.Id)" href="javascript:;" data-reason="@item.DisableReason" onclick="layer.alert($(this).attr('data-reason'))">原因</a>
                                        </td>
                                        <td>@item.OnLineTime</td>
                                        <td>@item.ActionTime</td>
                                        <td>@item.CreateTime</td>
                                        <td>
                                            <a class="btn btn-info btn-sm" href="@Url.Action("Edit","Users")?Id=@item.Id"><i class="fa fa-paste"></i> 编辑</a>
                                            <button class="btn btn-warning btn-sm delete_btn" type="button" data-id="@item.Id">
                                                <i class="fa fa-warning"></i> <span class="bold">删除</span>
                                            </button>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                </div>
            </div>
        </div>

    </div>
    <div class="row">
        <div class="col-sm-6">
            <div class="dataTables_info">共 @Model.TotalItemCount 项 @Model.TotalPageCount 页，当前第 @Model.CurrentPageIndex 页</div>
        </div>
        <div class="col-sm-6">
            <div class="dataTables_paginate paging_simple_numbers">
                <ul class="pagination">
                    @Html.Pager(Model, PageConfig.BackstageOptions)
                </ul>
            </div>
        </div>
    </div>
</div>
@section script_header
{
    <!--切换开关插件-->
    <link href="@Url.StaticFile("~/hplus/css/plugins/switchery/switchery.css")" rel="stylesheet">
}
@section script_footer
{
    <!--切换开关插件-->
    <script type="text/javascript" src="@Url.StaticFile("~/hplus/js/plugins/switchery/switchery.js")"></script>
    <script type="text/javascript">
    $(function () {
        /*通用删除操作*/
        ListTools.Delete.Init({ url: "@Url.Action("Delete","Users")", btn: ".delete_btn" });
        /*通用多选删除操作*/
        ListTools.Deletes.Init({ url: "@Url.Action("Deletes","Users")", btn: "#deletessubmit", itemname: "deleteitem" });
            /*选择操作*/
            ListTools.SelectBox.Init({ btn: "#selectdeleteitem", itemname: "deleteitem" });
            /*刷新操作*/
            ListTools.PageReload.Init({ btn: "#pagereload" });
            /***************************************************/
            /*
            *禁用
            *禁用时输入 理由
            */
            var elems = Array.prototype.slice.call(document.querySelectorAll('.disable-switch'));
            elems.forEach(function(checkbox) {
                var switchery = new Switchery(checkbox);
                checkbox.onchange = function() {
                    var id = $(this).attr("data-id");
                    this.checked ? disable(id) : noDisable(id);
                };
            });
            /*解除禁用*/
            var noDisable = function (id) {
                hgajax.postNoAlert("@Url.Action("Disable", "Users")", { id: id, disable: false }, function () {
                    $("#disable-refusereason" + id).addClass("hidden");
                });
            };
            /*禁用*/
            var disable = function (id) {
            hgajax.postNoAlert("@Url.Action("Disable", "Users")", { id: id, disable: true, reason: escape("暂无！") });
                layer.prompt({ title: '输入禁用原因', formType: 2 }, function(text, index) {
                    layer.close(index);
                    hgajax.postNoAlert("@Url.Action("Disable", "Users")", { id: id, disable: true, reason: escape(text) }, function () {
                        $("#disable-refusereason" + id).attr("data-reason", text);
                        $("#disable-refusereason" + id).removeClass("hidden");
                    });
                });
            };
            /***************************************************/
        })
</script>
}
